﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using LogicServer;
using Model;
using CommonCs;

namespace BugSysSolution.RequestAjaxPage
{
    public partial class FileAjaxPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String tag = Request.Form["tag"] ?? String.Empty;
            if (tag=="delfile")
            {
                DelFile();
            }
        }

        public void DelFile()
        {
            Users user = Session["user"] as Users;
            String fileurl = Request.Form["filename"] ?? String.Empty;
            String fileid = Request.Form["fileid"] ?? String.Empty;
            String path = Server.MapPath(@"~/" + fileurl);
            UpLoadFileLogic uf = new UpLoadFileLogic();
            bool bl = false;
            if (File.Exists(path))
            {
                File.Delete(path);
                bl = uf.DeleteFile(Convert.ToInt32(fileid));
                if (bl)
                {
                    Common.WriteFile(CommonCs.Exceptions.Operational, user.Uid, "删除上传文件[" + fileurl + "]成功,删除数据库记录成功!");
                    Response.Write("Success");
                }
                else
                {
                    Common.WriteFile(CommonCs.Exceptions.Operational, user.Uid, "删除上传文件[" + fileurl + "]成功,删除数据库记录成功!");
                    Response.Write("删除成功,更新数据失败!");
                }
            }
            else
            {
                Common.WriteFile(CommonCs.Exceptions.Operational, user.Uid, "需要删除的文件[" + fileurl + "]不存在!");
                Response.Write("指定文件不存在");
            }
        }
    }
}